//2009/08/30 02:02:41
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class CreateGroups
{
public:
    int minChanges(vector <int> groups, int minSize, int maxSize)
    {
		sort(groups.begin(), groups.end());
		int ret1 = 0;
		int ret2 = 0;
		int total = 0;
		for(int i=0; i<groups.size(); i++)
		{
			total += groups[i];
			if(groups[i] < minSize) ret1 += minSize - groups[i];
			if(groups[i] > maxSize) ret2 += groups[i] - maxSize;
		}
		if(total < minSize * groups.size() || total > maxSize * groups.size()) return -1;
		return max(ret1, ret2);
    }
};
